<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 400px;
            position: relative;
        }
        .p1{
            position: absolute;
            margin-left: 200px;
            margin-top: -22px;
            color: aqua;
        }
        .p2{
            
            color: rgb(255, 94, 0);
        }
        .p3{
            color: rgb(60, 255, 0);
        }
    </style>
</head>
<body>
    <div>
        <input type="password" value="">
        <p class="p1">请输入密码</p>
    </div>
    <script>
        var ipt = document.querySelector('input');
        var text = document.querySelector('.p1');
        ipt.onblur = function(){
            if(this.value.length<6||this.value.length>18){
                text.className = 'p1 p2';
                text.innerHTML = '密码输入错误';
            }else{
                text.className = 'p1 p3';
                text.innerHTML = '密码输入正确';
            }
        }
    </script>
</body>
</html>